/*
 *  Copyright (C) 2009  Peter Kist & Jan Ripke
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __logic_gamestate_manager_h
#define __logic_gamestate_manager_h 1

#include <boost/enable_shared_from_this.hpp>

#include <Core/Interface/Logic.h>
#include <Modules/Logic/Types.h>
#include <Modules/Logic/Gamestate/State.h>

#include <Core/Kernel/ModuleManager.h>

namespace galaxy {
    namespace logic {
        namespace gamestate {

            /** The entry point to the logic::gamestate module. It manages the mediator end-points
            * (consumer and producer) and the current state of the game.
            */
            class Manager : public boost::enable_shared_from_this<Manager>,
                public galaxy::ModuleManager
            {
                friend class LogicHandlerThread;

                StatePtr             m_CurrentState;
                ProducerPtr          m_Producer;
                
                LogicHandlerThread * m_LogicHandlerThread;  /**< thread that captures logic events */

            public:
                Manager(void);
                ~Manager(void);

                // ModuleManager interface
                virtual const char *    moduleName () { return "LOGIC Module"; };
                virtual bool            initialize ();
                virtual bool            postInitialize () { return true; };
                virtual boost::thread * startManagerThread ();
                virtual void            terminateThread ();
                virtual bool            preDestroy () { return true; };
                virtual bool            destroy () { return true; };

                /** Change to the specified game state. The current state is destroyed
                * @param stateName the name of the new state (@see State::Name)
                * @return true if state was successfully changed or false upon error.
                */
                bool changeState       (logic::State::Name& stateName);

                StatePtr& getCurrentState () { return m_CurrentState; };

            };

        } // namespace gamestate
    } // namespace logic
} // namespace galaxy

#endif // __logic_gamestate_manager_h
